package cn.wolfcode.designpattern.iterator;

import java.util.List;

/**
 * @author Leon
 * @date 2021/3/4
 * 具体迭代器
 */
public class BookIterator implements Iterator<Book> {

    private List<Book> books = null;
    private int index = -1;

    public BookIterator(List<Book> books) {
        this.books = books;
    }

    @Override
    public boolean hasNext() {
        return index < books.size() - 1;
    }

    @Override
    public Book first() {
        int FIRST_INDEX = 0;
        return books.get(FIRST_INDEX);
    }

    @Override
    public Book next() {
        if (this.hasNext()) {
            return books.get(++index);
        }

        return null;
    }
}
